home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / msm-2 / iconc.sit / tmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-19  |  2.6 KB  |  116 lines  |  [TEXT/MPS ]

  1. /*
  2.  * tmem.c -- memory initialization and allocation for the translator.
  3.  */
  4.  
  5. #include "::h:gsupport.h"
  6. #include "globals.h"
  7. #include "trans.h"
  8. #include "tsym.h"
  9. #include "tree.h"
  10. #include "tcode.h"
  11. #include "tproto.h"
  12.  
  13. struct centry *chash[CHSize];        /* hash area for constant table */
  14. struct fentry *fhash[FHSize];        /* hash area for field table */
  15. struct gentry *ghash[GHSize];        /* hash area for global table */
  16.  
  17. struct implement *bhash[IHSize];    /* hash area for built-in functions */
  18. struct implement *khash[IHSize];    /* hash area for keywords */
  19. struct implement *ohash[IHSize];    /* hash area for operators */
  20.  
  21. struct implement *spec_op[NumSpecOp];    /* table of ops with special syntax */
  22.  
  23. char pre[PrfxSz] = {'0', '0', '0'};     /* initial function name prefix */
  24.  
  25. extern struct str_buf lex_sbuf;
  26.  
  27.  
  28. /*
  29.  * init - initialize memory for the translator
  30.  */
  31.  
  32. novalue init()
  33. {
  34.    int i;
  35.  
  36.    init_str();
  37.    init_sbuf(&lex_sbuf);
  38.  
  39.    /*
  40.     * Zero out the hash tables.
  41.     */
  42.    for (i = 0; i < CHSize; i++)
  43.       chash[i] = NULL;
  44.    for (i = 0; i < FHSize; i++)
  45.       fhash[i] = NULL;
  46.    for (i = 0; i < GHSize; i++)
  47.       ghash[i] = NULL;
  48.    for (i = 0; i < IHSize; i++) {
  49.       bhash[i] = NULL;
  50.       khash[i] = NULL;
  51.       ohash[i] = NULL;
  52.       }
  53.  
  54.    /*
  55.     * Clear table of operators with non-standard operator syntax.
  56.     */
  57.    for (i = 0; i < NumSpecOp; ++i)
  58.       spec_op[i] = NULL;
  59.    }
  60.  
  61. /*
  62.  * init_proc - add a new entry on front of procedure list.
  63.  */
  64. novalue init_proc(name)
  65. char *name;
  66.    {
  67.    register struct pentry *p;
  68.    int i;
  69.    struct gentry *sym_ent;
  70.  
  71.    p = NewStruct(pentry);
  72.    p->name = name;
  73.    nxt_pre(p->prefix, pre, PrfxSz);
  74.    p->prefix[PrfxSz] = '\0';
  75.    p->nargs = 0;
  76.    p->args = NULL;
  77.    p->ndynam = 0;
  78.    p->dynams = NULL;
  79.    p->nstatic = 0;
  80.    p->has_coexpr = 0;
  81.    p->statics = NULL;
  82.    p->ret_flag = DoesRet | DoesFail | DoesSusp; /* start out pessimistic */
  83.    p->arg_lst = 0;
  84.    p->lhash = 
  85.      (struct lentry **)alloc((unsigned int)((LHSize)*sizeof(struct lentry *)));
  86.    for (i = 0; i < LHSize; i++)
  87.       p->lhash[i] = NULL;
  88.    p->next = proc_lst;
  89.    proc_lst = p;
  90.    sym_ent = instl_p(name, F_Proc);
  91.    sym_ent->val.proc = proc_lst;
  92.    }
  93.  
  94. /*
  95.  * init_rec - add a new entry on the front of the record list.
  96.  */
  97. novalue init_rec(name)
  98. char *name;
  99.    {
  100.    register struct rentry *r;
  101.    struct gentry *sym_ent;
  102.    static int rec_num = 0;
  103.  
  104.    r = NewStruct(rentry);
  105.    r->name = name;
  106.    nxt_pre(r->prefix, pre, PrfxSz);
  107.    r->prefix[PrfxSz] = '\0';
  108.    r->rec_num = rec_num++;
  109.    r->nfields = 0;
  110.    r->fields = NULL;
  111.    r->next = rec_lst;
  112.    rec_lst = r;
  113.    sym_ent= instl_p(name, F_Record);
  114.    sym_ent->val.rec = r;
  115.    }
  116.